#include "SoftTimer.h"

SoftTimerType SoftTimerBuf[TIMER_NUM];

void SoftTimerInit()
{
	unsigned char i=0;
	
	for(i=0;i<TIMER_NUM;i++)
	{
		SoftTimerClean(&SoftTimerBuf[i]);
	} 
}

void SoftTimerCntCheck(SoftTimerType *_timer,unsigned int interval)
{
	SoftTimerType *timer;
	timer=_timer;
	if(timer->TimerState==TimerEnable)
	{
		timer->TimerCnt+=interval;
		if(timer->TimerCnt>=timer->TimerSet)
		{
			timer->AlarmState=AlarmOn;
			timer->TimerState=TimerDisable;
		}
	}
}

void SoftTimerIntCallbackHandler(unsigned int intms)
{
	unsigned char i=0;
	
	for(i=0;i<TIMER_NUM;i++)
	{
		SoftTimerCntCheck(&SoftTimerBuf[i],intms);
	}
}

void SoftTimerSet(SoftTimerType *timer,unsigned int MsSet)
{
	timer->TimerState=TimerEnable;
	timer->AlarmState=AlarmOff;
	timer->TimerCnt=0;
	timer->TimerSet=MsSet;
}
void SoftTimerClean(SoftTimerType *timer)
{
	timer->TimerState=TimerDisable;
	timer->AlarmState=AlarmOff;
	timer->TimerCnt=timer->TimerSet=0;
}
